package com.h6.crm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.h6.crm.annotation.ResponseResult;
import com.h6.crm.entity.SysCity;
import com.h6.crm.entity.SysProvince;
import com.h6.crm.service.AreaService;
import com.h6.crm.util.pojo.R;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "区域管理", description = "区域管理的API")
@RestController
@RequestMapping("/area")
@ResponseResult
public class AreaController {

    @Autowired
    AreaService areaService;

    @Operation(summary = "查询省份")
    @ApiResponses({
            @ApiResponse(responseCode = "200", content = {
                    @Content(schema = @Schema(implementation = R.class), mediaType = "application/json") }) })
    @PostMapping("/province/list")
    public List<SysProvince> queryProvinceList() {
        return areaService.queryProvinceList();
    }

    @Operation(summary = "根据省份查询城市")
    @ApiResponses({
            @ApiResponse(responseCode = "200", content = {
                    @Content(schema = @Schema(implementation = R.class), mediaType = "application/json") }) })
    @PostMapping("/city/list")
    public List<SysCity> queryCityList(
            @Parameter(description = "省份ID", required = true) @RequestParam("provinceId") String provinceId) {
        return areaService.queryCityList(provinceId);
    }

}
